package com.wmh.baseservice.user.enums;

import java.util.Arrays;
import java.util.Objects;

public enum GroupGoodsOrderStatusEnum {
    TO_BE_PAID(0, "待支付"),
    TO_BE_DELIVERED(1, "待发货"),
    AWAITING_RECEIPT(2, "待收货"),
    AWAITING_PICKUP(3, "待提货"),
    PICKED_UP(4, "已提货"),
    BE_EVALUATED(5, "待评价"),
    COMPLETED(6, "已完成"),
    CANCELLED(-1, "已取消"),
    REFUNDED(-2, "已退款");

    private final Integer code;
    private final String description;

    GroupGoodsOrderStatusEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    public Integer getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static GroupGoodsOrderStatusEnum fromCode(Integer status) {
        return Arrays.stream(GroupGoodsOrderStatusEnum.values())
                .filter(statusEnum -> Objects.equals(statusEnum.code, status))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效的状态码: " + status));
    }
}